package com.miguo.utils;

import android.app.Activity;
import android.content.Context;
import android.graphics.Rect;
import android.util.DisplayMetrics;

/**
 * File Names: ScreenUtils
 * Describe:
 * User: LinXiaoZhi(87100854@qq.com)
 * Date: 2015-07-09
 * Time: 17:38
 */
public class ScreenUtils {

    public static int DENSITY_DPI = 0;
    public static int DENSITY_SIZE = 0;
    public static int HEIGHT = 0;
    public static int WIDTH;
    public static int STATUSUIBAR = 0;

    public static int dip2px(Context context, float px) {
        return (int) (px * context.getResources().getDisplayMetrics().density + 0.5F);
    }

    public static int px2dip(Context context, float dip) {
        return (int) (dip / context.getResources().getDisplayMetrics().density + 0.5F);
    }

    public static void setDisplay(Activity activity) {
        setContextDisplay(activity);
        Rect rect = new Rect();
        activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
        STATUSUIBAR = rect.top;
    }

    public static void setContextDisplay(Context context) {
        DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
        WIDTH = displayMetrics.widthPixels;
        HEIGHT = displayMetrics.heightPixels;
        DENSITY_DPI = displayMetrics.densityDpi;
        if (WIDTH >= 1080) {
            DENSITY_SIZE = 2;
            return;
        }
        if (WIDTH >= 720) {
            DENSITY_SIZE = 1;
            return;
        }
        DENSITY_SIZE = 0;
    }
}
